package com.shengde.jinwawaforleader.model.myJob.classList;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.shengde.jinwawaforleader.R;
import com.shengde.jinwawaforleader.base.BaseActivity;
import com.shengde.jinwawaforleader.model.myJob.adapter.MultiTypeAdapter;
import com.shengde.jinwawaforleader.network.BaseProtocol;
import com.shengde.jinwawaforleader.network.protocolbean.ProAssignTeaStuList;
import com.shengde.jinwawaforleader.utils.MessageEvent;
import com.shengde.jinwawaforleader.views.AddTeaStuPopupWindow;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.util.ArrayList;
import java.util.List;

public class ClassDetailsActivity extends BaseActivity {
	public int classid;
	public List<ProAssignTeaStuList.StuInfoEntity> stuInfoEntities;
	public List<ProAssignTeaStuList.TeacherInfoEntity> teacherInfoEntities;
	public ArrayList<String> allClass = new ArrayList<>();
	public ArrayList<Integer> allClassId = new ArrayList<>();
	public ArrayList<String> duty = new ArrayList<>();
	public MultiTypeAdapter adapter;
	private ClassDetailsActivity activity;
	public String classname;
	private TextView tv_title,tv_back,fill_add;
	private ListView lv;
	public int cnum;
	public int tnum;
	private LinearLayout loading_main;

	@Override
	public void onRoot(Bundle savedInstanceState) {
		//绑定事件接受
		EventBus.getDefault().register(this);
		setContentView(R.layout.activity_class_details);
		activity = this;
		Intent intent = getIntent();
		classid = intent.getIntExtra("classid", 0);
		classname = intent.getStringExtra("classname");
	}

	@Override
	public void initView() {
		tv_title = (TextView) findViewById(R.id.tv_title);
		tv_back = (TextView) findViewById(R.id.tv_back);
		lv = (ListView) findViewById(R.id.lv);
		fill_add = (TextView)findViewById(R.id.fill_add);
		loading_main = (LinearLayout) findViewById(R.id.loading_main);
	}

	@Override
	public void initData() {
		tv_title.setText(classname);
		fill_add.setText(getString(R.string.add));
		duty.add(getString(R.string.banzhuren));
		duty.add(getString(R.string.fudaolaoshi));
		BaseProtocol.getInstance().postTeaStuList(this, classid);
		BaseProtocol.getInstance().postAllClass(this);
	}

	@Override
	public void initListener() {
		tv_back.setOnClickListener(this);
		fill_add.setOnClickListener(this);
	}

	@Override
	public void onWidgetClick(View view) {
		switch (view.getId()) {
			case R.id.tv_back:
				finish();
				break;
			case R.id.fill_add:
				AddTeaStuPopupWindow popwindow = new AddTeaStuPopupWindow(this,classid);
				popwindow.showPopupWindow(findViewById(R.id.fill_add));
			    break;
		}
	}

	public void paddingData() {
		adapter = new MultiTypeAdapter(activity);
		lv.setAdapter(adapter);
		loading_main.setVisibility(View.GONE);
	}

	@Subscribe
	public void onMessageEvent(MessageEvent event) {
		if (MessageEvent.TIAOBANCHENGGONG.equals(event.message)||MessageEvent.SHANCHUERTONGXINXI.equals(event.message)) {
			BaseProtocol.getInstance().postTeaStuList(this, classid);
		}
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		//注销事件接受
		EventBus.getDefault().unregister(this);
	}
}